package cn.zzp.ggkt.vod.service.impl;

import cn.zzp.ggkt.model.vod.Teacher;
import cn.zzp.ggkt.vo.vod.TeacherQueryVo;
import cn.zzp.ggkt.vod.mapper.TeacherMapper;
import cn.zzp.ggkt.vod.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author zzp
 * @since 2022-08-21
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public IPage<Teacher> pageQuery(TeacherQueryVo queryVo) {
        // 创建page对象，传递当前页和每页显示条数
        Page<Teacher> page = new Page<>(queryVo.getCurrentPage(), queryVo.getPageSize());

        // 获取条件值
        Integer level = queryVo.getLevel();
        String name = queryVo.getName();
        String joinDateBegin = queryVo.getJoinDateBegin();
        String joinDateEnd = queryVo.getJoinDateEnd();

        // 封装条件对象
        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(name)) {
            wrapper.like("name",name);
        }
        if (!StringUtils.isEmpty(level)) {
            wrapper.eq("level", level);
        }
        if (!StringUtils.isEmpty(joinDateBegin)) {
            wrapper.ge("joinDateBegin", joinDateBegin);
        }
        if (!StringUtils.isEmpty(joinDateEnd)) {
            wrapper.le("joinDateEnd", joinDateEnd);
        }

        // 调用方法返回分页查询结果
        Page<Teacher> teacherPage = teacherMapper.selectPage(page, wrapper);
        return teacherPage;
    }
}
